package com.ruoyi.report.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.report.domain.temp.ZixiecheTaskRespDTO;
import com.ruoyi.report.service.IDataImportReportService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 数据导入报告Controller
 * 
 * @author luguanqing
 * @date 2020-11-30
 */
@Api(value="数据导入报告",tags = "数据导入报告")
@RestController
@RequestMapping("/data/import")
public class DataImportReportController extends BaseController
{
    @Autowired
    private IDataImportReportService dataImportReportService;

    /**
     * 根据报告编号获取信息
     */
    @PostMapping("/getZixiecheData")
    public AjaxResult getReportDataByReportNum(@RequestBody String reportNum) {
        return AjaxResult.success(dataImportReportService.getReportDataByReportNum(reportNum));
    }

    /**
     * 根据报告编号生成报告
     */
    @PostMapping("/generateZixiecheReport")
    public AjaxResult generateZixiecheReport(@RequestBody String reportNum) {
        String filePath = dataImportReportService.generateZixiecheReport(reportNum);
        if(StringUtils.isNotEmpty(filePath)) {
            return AjaxResult.success((Object) filePath);
        }
        return AjaxResult.error("生成报告失败");
    }

    /**
     * 自卸车数据信息保存
     */
    @PostMapping("/saveZixiecheData")
    public AjaxResult saveDataInfo(@RequestBody  ZixiecheTaskRespDTO zixiecheTaskRespDTO) {
        return toAjax(dataImportReportService.saveZixiecheData(zixiecheTaskRespDTO));
    }

    /**
     * 自卸车数据信息更新
     */
    @PutMapping("/updateZixiecheData")
    public AjaxResult updateDataInfo(@RequestBody  ZixiecheTaskRespDTO zixiecheTaskRespDTO) {
        return toAjax(dataImportReportService.updateZixiecheData(zixiecheTaskRespDTO));
    }

    /**
     * 根据报告编号删除数据
     */
    @DeleteMapping("/{reportNum}")
    public AjaxResult deleteReportDataByReportNum(@PathVariable String reportNum) {
        return toAjax(dataImportReportService.deleteReportDataByReportNum(reportNum));
    }

    /**
     * 根据word文件路径生成pdf文件
     */
    @PostMapping("/generatePdfFile")
    public AjaxResult generatePdfFile(@RequestBody String wordFilePath) {
        String filePath = dataImportReportService.generatePdfFile(wordFilePath);
        if(StringUtils.isNotEmpty(filePath)) {
            return AjaxResult.success((Object) filePath);
        }
        return AjaxResult.error("生成pdf文件失败");
    }

    /**
     * 自卸车数据信息保存
     */
    @PostMapping("/saveReport")
    public AjaxResult saveReport(@RequestBody  String reportNum) throws IOException {
        return toAjax(dataImportReportService.saveReport(reportNum));
    }
}
